/**
 * Created by BigBi on 2017/3/28.
 */

var http = require('http');

var server = http.createServer(function (req,res){
    res.writeHead(200, {'Content-Type':'text/plain'});
    res.end('hello world\n');
}).listen(3000);

//通过 on/once 为某事件注册一个监听器。

//每次有新的连接都会执行
server.on('connection',function(){
    console.log('someone has connected');
});

//只执行一次
server.once('connection',function(){
    console.log('welcome the first guy!');
})

// 终端打印如下信息
console.log('Server running at http://127.0.0.1:3000/');